#include "include\\Common.fxh"
/*
% Static Evironment Mapping.
date: 06/19/12
*/

/*****************Un-Twealables**********************************/
#define FLIP_TEXTURE_Y 1

//after colon is a semantic usefull later for knowing what variables this shader has
float4x4 WorldViewProjection : WORLDVIEWPROJECTION < string UIWidget="None";>;
float4x4 WorldInverseTranspose : WORLDINVERSETRANSPOSE < string UIWidget="None";>;
float4x4 World:WORLD <string UIWidget = "None";>;
float4x4 ViewInverse:VIEWINVERSE <string UIWidget = "None";>;

/****************Tweakables************************************/
texture ColorTexture : COLOR 
< 
	string UIName = "Color Texture";
	string ResourceType = "3D";
>;

float4 AmbientColor : COLOR
<
	string UIName = "Ambient Color";
	string UIWidget = "Color";
	
> = {1.0f,1.0f,1.0f,1.0f}; //default value

float4 EnvColor
<
	string UIName = "Environment Color";
	string UIWidget = "Color";
> = {1.0f,1.0f,1.0f,1.0f}; //default value
/***************Un-Tweakable************************************/
samplerCUBE ColorSampler = sampler_state
{	
	Texture = <ColorTexture>; //the texture it will be grabbing pixel date from
	Magfilter = LINEAR;		  //zoom in - does linear interpelation
	Minfilter = LINEAR;		  //zoom out
	Mipfilter = LINEAR;
	AddressU = MIRROR;		  //wrap or clamp
	AddressV = MIRROR;		  //uv values or 0 to 1 oustide that they must either be wrapped(round up to the next) or clamped(made to fit in 0to1)
	AddressW = MIRROR;
};

texture EnvironmentMap : ENVMAP 
<
	string UIName = "Environment Map";
	string ResourseType = "3D";
>;

sampler EnvironmentMapSampler = sampler_state
{
	Texture = <EnvironmentMap>;
	Magfilter = LINEAR;		  //zoom in - does linear interpelation
	Minfilter = LINEAR;		  //zoom out
	AddressU = Clamp;		  //wrap or clamp
	AddressV = Clamp;		  //uv values or 0 to 1 oustide that they must either be wrapped(round up to the next) or clamped(made to fit in 0to1)
	AddressW = Clamp;
};

/*****************Data Structures****************************/
struct VS_INPUT
{
	float4 ObjectPosition: POSITION0;
};
struct VS_OUTPUT
{
	float4 ScreenPosition: POSITION0;
	float3 TextureCoordinate: TEXCOORD0;
};
struct PS_OUTPUT
{
	float4 Color:COLOR0;
};

/*****************Vertex Shader*****************************/
VS_OUTPUT vertex_shader(VS_INPUT IN)
{
	VS_OUTPUT OUT = (VS_OUTPUT)0; //memset clear garbage
	OUT.ScreenPosition = mul(IN.ObjectPosition, WorldViewProjection);
	
	float4 worldPosition = mul(IN.ObjectPosition,World);
	float3 eyePosition = ViewInverse[3].xyz;
	OUT.TextureCoordinate = normalize(worldPosition - eyePosition);
	
	return OUT;
}

/*****************Pixel Shader*******************************/
float4 pixel_shader(VS_OUTPUT IN) : COLOR
{
	return texCUBE(ColorSampler,IN.TextureCoordinate);
}

/****************Techniques**********************************/
technique main
{
	pass p0 
	{
		VertexShader = compile vs_3_0 vertex_shader();
		PixelShader = compile ps_3_0 pixel_shader();
	}
}
